package com.fingard.dsp.bank.directConfig;

import java.util.ArrayList;
import java.util.HashMap;

import com.fingard.dsp.bankset.BankFront;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;

public class TaskTimerSet {
    /*        <taskTimer enable="true" readme="定时作业">
                <intervalSecs readme="轮询间隔时间：秒，小于等于0则不启动">60</intervalSecs>
                <taskNameList>getNewNotice</taskNameList>
            </taskTimer>
     * */
    public boolean enable = false;
    public long intervalSecs = 0;
    public String taskNameList;
    public BankFront bankFront;
    
    public HashMap<String,String> taskParams;

    public void fromXElement(XElement p_XE) throws NumberFormatException, Exception {
        enable = p_XE.getAttrValueAsBool("enable");
        intervalSecs = Long.parseLong(p_XE.getSingleTextNotNull("intervalSecs"));
        taskNameList = p_XE.getSingleTextNotNull("taskNameList").trim();
        
        HashMap<String,String> params = new HashMap<String,String>();
		XElement paramList = p_XE.getSingleChild("paramList");
		if(paramList != null){
			ArrayList<XElement> xeParams = paramList.getAllChildList();
			if(xeParams != null && xeParams.size()>0){
				for(XElement eachPm : xeParams){
					params.put(eachPm.name.toLowerCase(), eachPm.innerText);
				}
			}
		}
		taskParams = params;
    }
    
    /**获取int参数*/
	public int getParamAsInt(String pKey, int pDefVal){
		if(StringHelper.hasAnyChar(pKey)){
			String keyLw = pKey.toLowerCase();
			if(taskParams != null && taskParams.containsKey(keyLw)){
				String tmpVal = taskParams.get(keyLw);
				if(StringHelper.hasAnyChar(tmpVal)){
					return Integer.parseInt(tmpVal);
				}
			}
		}
		return pDefVal;
	}
}
